/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Text, LineColumn, InputLine, SuffixInput, Table, TableBody, TableRow, CCell, InputDatalist,
} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, RepLink, useItemInputControl,} from "../../common/base";
import {useMeasureInpFilter} from "../../common/hooks";
import {floatInterception} from "../../../common/tool";
import {检验结果选} from "./SpeedBias";

export const itemA扶速差=['扶行距离','左错位距','右错位距','扶速差r','仪左错距','仪右错距','仪扶差r'];
export const HandrailBias=
    React.forwardRef(({ children, show ,alone=true,refWidth,label}:InternalItemProps,  ref
    ) => {
        const [getInpFilter]=useMeasureInpFilter(null, itemA扶速差, );
        const {inp, setInp} = useItemInputControl({ ref });
        const speedVs= floatInterception(inp?.行距离 / inp?.用时间, 4) as unknown as number;
        const resPec=floatInterception(100*(speedVs-inp?.运行速度)/inp?.运行速度, 2);
        const resPec2=floatInterception(100*(inp?.仪速度偏-inp?.运行速度)/inp?.运行速度, 2);
        return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={label!}>
                <Text variant="h5">{label}</Text>
                <Text variant="h5">空载梯级（踏板、胶带）和扶手带运行速度偏差（简易方法）{'>>'}</Text>
                <LineColumn>
                    <InputLine label='实际运行距离S(mm)'>
                        <SuffixInput value={inp?.扶行距离 ?? ''}
                                     onSave={txt => setInp({...inp, 扶行距离: txt || undefined})}>mm</SuffixInput>
                    </InputLine>
                    <InputLine label='左侧扶手带与梯级（踏板、胶带）错位距离Sl(mm)'>
                        <SuffixInput value={inp?.左错位距 ?? ''}
                                     onSave={txt => setInp({...inp, 左错位距: txt || undefined})}>mm</SuffixInput>
                    </InputLine>
                    <InputLine label='右侧扶手带与梯级（踏板、胶带）错位距离Sr(mm)'>
                        <SuffixInput value={inp?.右错位距 ?? ''}
                                     onSave={txt => setInp({...inp, 右错位距: txt || undefined})}>mm</SuffixInput>
                    </InputLine>
                </LineColumn>
                <div css={{textAlign: 'center'}}>
                    左侧扶手带速度偏差δl； δl=Sl/S
                    计算结果：{floatInterception(100 * inp?.左错位距 / inp?.扶行距离, 2)} %;<br/>
                    右侧扶手带速度偏差δr； δr=Sr/S
                    计算结果：{floatInterception(100 * inp?.右错位距 / inp?.扶行距离, 2)} %;
                    <Text variant="h6">判断标准 允许偏差为0-+2%</Text>
                </div>
                <InputLine label={'检验结果'}>
                    <InputDatalist value={inp?.扶速差r ?? ''} datalist={检验结果选}
                                   onListChange={v => setInp({...inp, 扶速差r: v || undefined})}/>
                </InputLine>
                <hr/>
                <Text variant="h5" css={{
                    marginTop: '1rem',
                }}>空载梯级（踏板、胶带）和扶手带运行速度偏差（自动扶梯综合检测仪等其他仪器）{'>>'}</Text>
                <LineColumn>
                    <InputLine label='左侧扶手带速度偏差δl；δl=Sl/S'>
                        <SuffixInput value={inp?.仪左错距 ?? ''}
                                     onSave={txt => setInp({...inp, 仪左错距: txt || undefined})}>%</SuffixInput>
                    </InputLine>
                    <InputLine label='右侧扶手带速度偏差δr；δr=Sr/S'>
                        <SuffixInput value={inp?.仪右错距 ?? ''}
                                     onSave={txt => setInp({...inp, 仪右错距: txt || undefined})}>%</SuffixInput>
                    </InputLine>
                </LineColumn>
                <Text variant="h6" css={{textAlign: 'center'}}>判断标准 允许偏差为0-+2%</Text>
                <InputLine label={'检验结果'}>
                    <InputDatalist value={inp?.仪扶差r ?? ''} datalist={检验结果选}
                                   onListChange={v => setInp({...inp, 仪扶差r: v || undefined})}/>
                </InputLine>
                <br/>
            </InspectRecordLayout>
    );
});


export const 扶手带速度偏差= ({orc, rep,label} :{orc:any, rep:any,label:string}
) => {
    return <>
        <div css={{"@media print": {paddingBottom: '7rem', pageBreakInside: 'avoid'}}}>
            <Text id={'HandrailBias'} variant="h4" css={{marginTop: '1rem',
            }}>{label}</Text>
        </div>
        <Table fixed={ ["20%","27%","12%","13%","%"] }
               css={{borderCollapse: 'collapse', "@media print": {marginTop: '-7rem'}}} tight miniw={800}>
            <TableBody>
                <RepLink rep={rep} tag={'HandrailBias'}>
                    <TableRow><CCell>项目编号</CCell><CCell colSpan={4}>42.8</CCell></TableRow>
                    <TableRow><CCell>检验内容</CCell><CCell>实际运行距离S(mm)</CCell>
                        <CCell colSpan={2}>左侧扶手带与梯级（踏板、胶带）错位距离Sl(mm)</CCell><CCell>右侧扶手带与梯级（踏板、胶带）错位距离Sr(mm)</CCell>
                    </TableRow>
                    <TableRow><CCell>观测数据</CCell><CCell>{orc.扶行距离 ?? '／'} mm</CCell>
                        <CCell colSpan={2}>{orc.左错位距 ?? '／'} mm</CCell><CCell>{orc.右错位距 ?? '／'} mm</CCell>
                    </TableRow>
                    <TableRow><CCell rowSpan={2}>计算结果：</CCell><CCell colSpan={2}>左侧扶手带速度偏差δl；δl=Sl/S</CCell><CCell colSpan={2}>右侧扶手带速度偏差δr；δr=Sr/S</CCell></TableRow>
                    <TableRow><CCell colSpan={2}>{floatInterception(100*orc?.左错位距/orc?.扶行距离, 2)} %</CCell>
                        <CCell colSpan={2}>{floatInterception(100*orc?.右错位距/orc?.扶行距离, 2)} %</CCell>
                    </TableRow>
                    <TableRow><CCell>判断标准</CCell><CCell colSpan={4}>允许偏差为0-+2%</CCell></TableRow>
                    <TableRow><CCell>检验结果</CCell><CCell colSpan={4}>{orc.扶速差r ?? '／'}</CCell></TableRow>
                </RepLink>
            </TableBody>
        </Table>

        <div css={{"@media print": {paddingBottom: '5rem', pageBreakInside: 'avoid'}}}>
            <Text variant="h5" css={{marginTop: '1rem',
            }}>空载梯级（踏板、胶带）和扶手带运行速度偏差（自动扶梯综合检测仪等其他仪器）</Text>
        </div>
        <Table fixed={ ["22%","39%","%"] }
               css={{borderCollapse: 'collapse', "@media print": {marginTop: '-5rem'}}} tight miniw={800}>
            <TableBody>
                <RepLink rep={rep} tag={'HandrailBias'}>
                    <TableRow><CCell>项目编号</CCell><CCell colSpan={2}>42.8</CCell></TableRow>
                    <TableRow><CCell rowSpan={2}>计算结果：</CCell><CCell>左侧扶手带速度偏差δl；δl=Sl/S</CCell><CCell>右侧扶手带速度偏差δr；δr=Sr/S</CCell></TableRow>
                    <TableRow><CCell>{orc?.仪左错距?? '／'} %</CCell><CCell>{orc?.仪右错距?? '／'} %</CCell></TableRow>
                    <TableRow><CCell>判断标准</CCell><CCell colSpan={2}>允许偏差为0-+2%</CCell></TableRow>
                    <TableRow><CCell>检验结果</CCell><CCell colSpan={2}>{orc.仪扶差r ?? '／'}</CCell></TableRow>
                </RepLink>
            </TableBody>
        </Table>
    </>;
};
